﻿<!DOCTYPE html>
<html>
<head>
    <title>{$platform.name}</title>
    <link href="/static/css/framework-font.css" rel="stylesheet"/>
    <script src="/static/js/jquery-2.1.1.js"></script>
    <script src="/static/bootstrap/js/bootstrap.js"></script>
    <link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>

    <script src="/static/js/jquery.cookie.js"></script>
    <link href="/static/css/framework-theme.css" rel="stylesheet"/>
    <script src="/static/js/framework-ui.js"></script>
    <script src="/static/js/framework-clientdata.js"></script>

    <!--弹框js-->
    <script src="/static/js/yii.js"></script>

    <!--引用layui弹框插件-->
    <script src="/static/layui/layui.all.js"></script>
    <script src="/static/layui/layui.js"></script>
    <link href="/static/layui/css/layui.css" rel="stylesheet"/>
    <script src="/static/layui/lay/modules/layer.js"></script>



    <!--开关主键-->
    <script src="/static/bootstrap/bootstrap-switch.js"></script>
    <link href="/static/bootstrap/bootstrap-switch.css" rel="stylesheet"/>

<!--    配置select多选相关-->
    <script src="/static/layui/dist/xm-select.js"></script>


        {if condition="$swidthStyle eq 0"}
    <link href="/static/css/pattern/public.css" rel="stylesheet"/>
    {else/}
        {if condition="$swidthStyle eq 0"}
    <link href="/static/css/pattern/public.css" rel="stylesheet"/>
    {else/}
    <link href="/static/css/default/public.css" rel="stylesheet"/>
    {/if}
    {/if}
</head>
<body>

<div class="newtest">

    <div class="container new_serach">
    {volist name="powerList" id="vo"}
    <a class="btn btn-primary btn-sm" href="{$vo['url']}">{$vo.name}</a>
    {/volist}
    </div>

    <div class="container new_serach">
        <span> 账号：</span>
        <div class="layui-inline">
            <input class="layui-input" name="keyword"  value="{$keyword}" autocomplete="off">
        </div>

        <span> 手机号：</span>
        <div class="layui-inline">
            <input class="layui-input" name="phone"  value="{$phone}" autocomplete="off">
        </div>

        <span> 代理区域：</span>
        <div class="layui-inline">
            <input class="layui-input" name="area"  value="{$area}" autocomplete="off">
        </div>

        <span> 添加时间：</span>
        <div class="layui-inline">
            <input class="layui-input" name="time" id="test6"  value="{$time}" autocomplete="off">
        </div>

        <button class="layui-btn layui-btn-sm" data-type="reload">搜索</button>
    </div>


    <div class="new_main">

        <table class="layui-hide" id="demo" lay-filter="demo"></table>

        <script type="text/html" id="switchTpl">
            <!--启用禁用操作-->
            <input type="checkbox" name="status" value="{{d.a_id}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="sexDemo" {{ d.a_status == 1 ? 'checked' : '' }}>
        </script>

        <script type="text/html" id="barDemo">
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
        </script>


        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="getCheckLength">批量删除</button>
            </div>
        </script>

    </div>
</div>




</body>
<script src="/static/js/index.js"></script>
<script src="/static/js/indextab.js"></script>
<script src="/static/js/pace.min.js"></script>
<script>
    layui.use(['form','jquery','layer','laydate','table'], function() { //独立版的layer无需执行这一句
        var $ = layui.jquery, layer = layui.layer;
        var form = layui.form;
        var laydate = layui.laydate;
        var table = layui.table //表格
        //日期范围
        laydate.render({
            elem: '#test6'
            , range: true
        });


        //搜索操作
        $('.layui-btn').click(function () {
            var keyword = $('input[name="keyword"]').val();
            var phone = $('input[name="phone"]').val()
            var area = $('input[name="area"]').val()
            var time = $('input[name="time"]').val()
            table.reload('demo', {
                url: "{:URL('admin/city/index')}"
                // ,methods:"post"
                , request: {
                    pageName: 'page' //页码的参数名称，默认：page
                    , limitName: 'pageSize' //每页数据量的参数名，默认：limit
                }
                , where: {
                    keyword: keyword,
                    phone: phone,
                    area: area,
                    time: time
                }
                , page: {
                    curr: 1
                }
            });
        });

        table.render({
            toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
            defaultToolbar: ['filter', 'exports', 'print'],
            elem: '#demo', // 表格id
            url:"{:URL('admin/city/index')}",
            where:{type:'list'},
            title: '入驻城市数据表',
            page: true, // 树形表格一般是没有分页的
            cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field: 'a_id', title: 'ID',  sort: true, fixed: 'left',width:80}
                ,{field: 'name', title: '账号',width:150}
                ,{field: 'company', title: '公司名称', sort: true, totalRow: true}
                ,{field: 'province_name', title: '代理区域', sort: true,}
                ,{field: 'addtime', title: '添加时间', width: 170}
                ,{field: 'a_status', title: '状态', width: 135, sort: true,templet: '#switchTpl', unresize: true}
                ,{fixed: 'right',title: '操作', width: 165, align:'center', toolbar: '#barDemo'}
            ]],
            done: function() {
                layer.closeAll('loading');
            }
        });

        //监听启用禁用操作
        form.on('switch(sexDemo)', function(obj){
            var id = this.value;
            var state = obj.elem.checked;
            if (state == true) {
                //上线
                updateProductStatus(id,'1');
            } else {
                //下线
                updateProductStatus(id,'2');
            }
        });

        //监听行工具事件
        table.on('tool(demo)', function(obj){
            switch(obj.event){
                case 'del':
                var id = obj.data.a_id;
                layer.confirm('真的删除行么', function(index){
                    var newthat = $(this);
                    $.ajax({
                        type: "post",
                        url: "{:URL('admin/city/delCity')}",
                        data: {id:id},
                        dataType: "json",
                        success: function(data){
                            layer.alert(data.msg);
                            if(data.code==0){
                                obj.del();
                                layer.close(index);
                            }
                        }
                    });
                });
                break;
            };
        });



        //批量删除
        table.on('toolbar(demo)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckLength':
                    var data = checkStatus.data;
                    var id=[];
                    for (var i = 0; i < data.length; i++) {
                        id[i] = data[i].a_id;
                    }
                    layer.confirm('真的删除行么', function(index){
                        var newthat = $(this);
                        $.ajax({
                            type: "post",
                            url: "{:URL('admin/agent/delAgent')}",
                            data: {id:id},
                            dataType: "json",
                            success: function(data){
                                layer.alert(data.msg);
                                if(data.code==0){
                                    //执行重载
                                    table.reload('demo');
                                    layer.close(index);
                                }
                            }
                        });
                    });
                    break;
            };
        });




    });




    //更改状态
    function updateProductStatus(id,status) {
        $.ajax({
            type: "post",
            url: "{:URL('admin/city/clickStatus')}",
            data: {id:id,status:status},
            dataType: "json",
            success: function(data){}
        });
    }

</script>

</html>
